﻿using LuDragon.Common.Constant;
using LuDragon.Common.Enums;
using LuDragon.Common.Utils;
using LuDragon.Data.Entities;
using LuDragon.IService.System;
using LuDragon.Service.System;
using LuDragon.Web.Areas.Admin.Filters;
using Newtonsoft.Json;
using System.Web.Mvc;

namespace LuDragon.Web.Areas.Admin.Controllers
{

    public class BaseController : Controller
    {
        protected Sys_User AdminInfo;
        protected ILogService logger = new LogService();
        public BaseController()
        {
            IUserService userService = new UserService();
            AdminInfo = userService.GetCurrentUser();
        }
    
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ActionResult Success(object data = null, string msg = "操作成功")
        {
            var result = new HttpResult
            {
                Code = 200,
                Msg = msg,
                Data = data
            };
            return Content(JsonConvert.SerializeObject(result));
        }
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="actionName">操作名称</param>
        /// <param name="actionType">操作类型</param>
        /// <param name="remark">备注</param>
        public void WriteLog(string actionName, LogMode actionType, string remark = "")
        {
            logger.WriteLog(actionName, actionType, AdminInfo, remark);
        }
        /// <summary>
        /// 分页查询成功
        /// </summary>
        /// <returns></returns>
        public ActionResult PageQuerySucess(int count, object data, string msg = "Success")
        {
            var result = new PageQueryRespone
            {
                Count = count,
                Data = data,
                Msg=msg
            };
            return Content(JsonConvert.SerializeObject(result));
        }
    }
}